package org.flexlancer.utils
{
	import components.twShowAction;
	
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	
	import org.flexlancer.Logger.Logger;
	
	public class GeneralUtils
	{
		private static var msgList:Array = new Array;
		private static var window:twShowAction;
		public static var parentComponent:UIComponent;
		private static var curr_req:int;
		
		public static function Show(parmMsg:String):void{
			try{
				if ( window == null ){
					window = PopUpManager.createPopUp(parentComponent,twShowAction,true) as twShowAction;
					PopUpManager.centerPopUp(window);
					msgList = new Array;
					curr_req = 0; 
				}
				
				msgList.push(parmMsg);
				
				UpdateInfo();
				window.pbTotal.setProgress(curr_req+1,msgList.length);
			}catch(err:Error){
				Logger.LogE(err);
			}
		}
		
		private static function UpdateInfo():void{
			try{
				window.pbDetail_lbl = msgList[curr_req];
				window.pbTotal_lbl = (curr_req+1).toString() + " of " + msgList.length.toString();
			}catch(err:Error){
				Logger.LogE(err);
			}
		}
		
		public static function Hide():void{
			try{
				curr_req ++;
				window.pbTotal.setProgress(curr_req+1,msgList.length);
				
				if ( curr_req >= msgList.length ){
					PopUpManager.removePopUp(window);
					window = null;
				}else{
					UpdateInfo();
				}
			}catch(err:Error){
				Logger.LogE(err);
			}
		}
	}
}